<html>
    <head>
        <title></title>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
         <?php include "jquery.php"; ?>
        <link href="style3.css" rel="stylesheet" type="text/css" />
          <script>
//this part of the code is for hiding and showing the tables of authors and reviewers on clicking them
        $(document).ready(function(){
$(".flip1").click(function(){
    $(".panel1").slideToggle("slow");
  });
$(".flip2").click(function(){
    $(".panel2").slideToggle("slow");
  });
});
</script>
<style type="text/css">
p.flip1
{
    cursor: pointer;
margin:0px;
padding:5px;
text-align:center;
background:white;
border:solid 1px #c3c3c3;
}
div.panel1
{
height: 200px;
display:none;
overflow: auto;
}
p.flip2
{
cursor: pointer;
margin:0px;
padding:5px;
text-align:center;
background:white;
border:solid 1px #c3c3c3;
}
div.panel2
{
height: 200px;
display:none;
overflow: auto;
}
</style>
    </head>
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db('mydb');
session_start();
$member_id= $_SESSION['member_id'];
$confID = $_POST['conference'];

//get the authors for a given conference
$query1 = "SELECT M.first_name, M.last_name, M.member_id
          FROM Member M INNER JOIN member_privileges MP
          ON M.member_id = MP.member_id
          INNER JOIN privileges Pr
          ON MP.privileges_id = Pr.privileges_id
          WHERE MP.conference_id = $confID
          AND Pr.role = 'author'
          AND M.member_id <> {$member_id}";
//get the reviewers of a given conference
$query2 = "SELECT M.first_name, M.last_name, M.member_id
           FROM Member M
           INNER JOIN member_privileges MP
           ON M.member_id = MP.member_id
           INNER JOIN privileges Pr
           ON MP.privileges_id = Pr.privileges_id
           WHERE MP.conference_id = $confID
           AND Pr.role = 'reviewer'
           AND M.member_id <> {$member_id}";


echo "<form name='fRadio' method='POST' action='send.php?conference={$confID}'>";
echo "<fieldset>";
echo "<legend>Create new message</legend>";
//populates the authors table with authors of this conference
$authors = mysql_query($query1) or die(mysql_error());
if ($authors)
{
    echo '<p class="flip1">Choose Authors</p>';
     echo "<div class='panel1'>";
    print "<table width=100%; border=1>\n";
    print "<tr>\n";

    print "<th>&nbsp; </th>\n";
    print "<th><width=\"0%\" height=\"0\" style=\"display:none\" value=\"Member ID\"</th>\n";
    print "<th> Author Name </th>\n";

    print "</tr>\n";
    //create table
    $i = 0;
    while ( $row = mysql_fetch_array($authors) ) {
        $i++;
        print "<tr>\n";
        print "<td><input type=\"checkbox\" name=\"authors[]\" value=\"$row[member_id]\"></td>\n";
        echo "<td><width=\"0%\" height=\"0\" style=\"display:none\" value=\"{$row['member_id']}\"</td>\n";
        echo "<td>{$row['first_name']} {$row['last_name']}</td>\n";

        echo "</tr>\n";
    }//end while
print "</table>\n";
echo '</div>';

//populates the reviewers table with reviewers of this conference
$reviewers = mysql_query($query2) or die(mysql_error());
if ($reviewers)
{
     echo '<p class="flip2">Choose Reviewers</p>';
     echo "<div class='panel2'>";
    print "<table width=100%; border=1>\n";
    print "<tr>\n";
    print "<th>&nbsp; </th>\n";
    print "<th><width=\"0%\" height=\"0\" style=\"display:none\" value=\"Member ID\"</th>\n";
    print "<th> Reviewer Name </th>\n";

    print "</tr>\n";
    //create table
    $i = 0;
    while ( $row = mysql_fetch_array($reviewers) ) {
        $i++;
        print "<tr>\n";
        print "<td><input type=\"checkbox\" name=\"reviewers[]\" value=\"$row[member_id]\"></td>\n";
        echo "<td><width=\"0%\" height=\"0\" style=\"display:none\" value=\"{$row['member_id']}\"</td>\n";
        echo "<td>{$row['first_name']} {$row['last_name']}</td>\n";

        echo "</tr>\n";
    }//end while
print "</table>\n";
echo '</div>';
}
}
mysql_close($con);
?>

<!--functions to activate the text box-->
<script>
 //activates the text box on selecting the thank you template and changes the text inside according to the template
 function activateThankYou()
 {
  document.forms[0].TextBox.disabled=false;
  document.forms[0].TextBox.value="thank you for the reviews";

  document.forms[0].Message.disabled=false;

  for(var i=0;i<document.forms[0].elements.length;i++)
  {
    if(document.forms[0].elements[i].name=="dOption")
    {
     if(document.forms[0].elements[i].value=="N")
     {
       if(document.forms[0].elements[i].checked==true)
       {
           document.forms[0].TextBox.disabled=false;
            document.forms[0].TextBox="thank you for the reviews";
            document.forms[0].Message.disabled=false;
       }
     }
    }
  }
 }
 //activates the text box on selecting the reminder template and changes the text inside according to the template
 function activateReminder()
 {
  // initialize form with empty field

  document.forms[0].TextBox.disabled=false;
  document.forms[0].TextBox.value="we would like to remind you that the deadline for ... is on the ...";

  document.forms[0].Message.disabled=false;

  for(var i=0;i<document.forms[0].elements.length;i++)
  {
    if(document.forms[0].elements[i].name=="dOption")
    {
     if(document.forms[0].elements[i].value=="T")
     {
       if(document.forms[0].elements[i].checked==true)
       {
            document.forms[0].TextBox.disabled=false;
            document.forms[0].TextBox.value="we would like to remind you that the deadline for ... is on the ...";
            document.forms[0].Message.disabled=false;
       }
     }
    }
  }
 }
  //activates the text box on selecting the empty template and changes the text inside according to the template
function activateEmpty()
{
    document.forms[0].TextBox.disabled=false;
    document.forms[0].TextBox.value=".....";

    document.forms[0].Message.disabled=false;

    for(var i=0;i<document.forms[0].elements.length;i++)
    {
        if(document.forms[0].elements[i].name=="dOption")
        {
            if(document.forms[0].elements[i].value=="T")
            {
                if(document.forms[0].elements[i].checked==true)
                {
                    document.forms[0].TextBox.disabled=false;
                    document.forms[0].TextBox.value="....";
                    document.forms[0].Message.disabled=false;
                }
            }
        }
    }
}
//creating the radio button list and the text box
</script>

    <p align="left">Subject:<input name="subject" value="" type="text"></p>
    <input name="dOption" value="N" onClick="activateThankYou()" type="radio"> Thank You Template
    <input name="dOption" value="T" onClick="activateReminder()" type="radio"> Reminder Template
    <input name="dOption" value="T" onClick="activateEmpty()" type="radio"> Empty Template<br/>
    <textarea style="width: 100%" name="TextBox" rows="8" cols="175" disabled="disabled" type="text" value=""></textarea><br/>
    <input name="Message" value="Send" disabled="disabled" type="submit" >
</fieldset>
  </form>
</body>
</html>



